<?php
class ControllerArticleColumnLeft extends Controller {
	public function index() {

		if (isset($this->request->get['route'])) {
			$route = $this->request->get['route'];
		} else {
			$route = 'common/home';
		}

		$layout_id = 0;

		if (substr($route, 0, 16) == 'article/category' && isset($this->request->get['path'])) {

            $this->data['heading_title'] = '目录';
            $path = explode('_', (string)$this->request->get['path']);

            if (isset($this->request->get['path'])) {
                $parts = explode('_', (string)$this->request->get['path']);
            } else {
                $parts = array();
            }

            if (isset($parts[0])) {
                $this->data['category_id'] = $parts[0];
            } else {
                $this->data['category_id'] = 0;
            }

            if (isset($parts[1])) {
                $this->data['child_id'] = $parts[1];
            } else {
                $this->data['child_id'] = 0;
            }

            $this->load->model('article/category');
            $this->load->model('article/article');
            $this->data['categories'] = array();

            $categories = $this->model_article_category->getCategories(0);

            foreach ($categories as $category) {
                $children_data = array();

                $children = $this->model_article_category->getCategories($category['category_id']);

                foreach ($children as $child) {

                    $children_data[] = array(
                        'category_id' => $child['category_id'],
                        'name'        => $child['name'],
                        'href'        => $this->url->link('article/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
                    );
                }

                $this->data['categories'][] = array(
                    'category_id' => $category['category_id'],
                    'name'        => $category['name'],
                    'children'    => $children_data,
                    'href'        => $this->url->link('article/category', 'path=' . $category['category_id'])
                );
            }

            $this->template = 'article/category_left.tpl';
            $this->render();
		}

		if (substr($route, 0, 15) == 'article/article' && isset($this->request->get['article_id'])) {
            
            $this->data['heading_title'] = '最新文章';
            $this->template = 'article/article_left.tpl';
            $this->render();
		}
	}
}
?>